public class Threadtest3 {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = new Thread();
        Thread t = new Thread(()->{
            System.out.println("this is Thread t");
            for (int i = 0; i < 5; i++) {
                System.out.println("t is working...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("Thread t is finished!!!");
        });

        t.start();

        System.out.println("The main thread is waitiing!!!");
        try {
            t.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("The main thread is after waiting!!!");
    }
}
